package com.ibm.productivity.tools.blogplugin;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

public class LocalSaver {
	public static final String PATH = "c:\\bbb\\";
	public static String filename;
	public static boolean saveFile(int id, String title, String content){
		File file = new File(PATH);
		if (file.exists()==false) {
			System.out.println("not exist");
			if (file.mkdir()==false) {
				System.out.println("fail to make");
				return false;
			}
			System.out.println("success to make");
		}
		
		if (content == "") return false;
		filename = String.format("%s%d.txt", PATH, id);
		try {
			PrintWriter out = new PrintWriter(new FileOutputStream(filename));
			out.println("Title:"+title);
			out.println();
			out.println(content);
			out.close();
			saveInfo();
			return true;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}	
	}
	
	private static void saveInfo(){
		System.out.println(filename+" saved.");
	}
	
	public static void main(String[] args) {
		if (LocalSaver.saveFile(1, "abc", "content"))
			System.out.println(LocalSaver.filename+" saved.");
		else
			System.out.println("error occured");
				
	}
}


